<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/12/6
 * Time: 10:33
 */

if(empty($_POST['user'])){
    echo '用户名不能为空';
}
if(empty($_POST['pwd'])){
    echo '密码不能为空';
}

//1.登入判断
//2.登入成功，则设置一个cookies,名字：Token,值md5(用户名+密码+时间戳),效期：24小时
$user = $_POST['user'];
$pwd = $_POST['pwd'];

if($user=='admin' && $pwd=='888888'){
    echo '登入成功<br />';
    $md5=md5($user.$pwd.time());
    setcookie('Token',$md5,time()+24*3600);

    if(!empty($_COOKIE['Token'])){
        echo 'cookies存在';
    }else{
        echo 'cookies不存在';
    }
}else{
    echo '账号或者密码错误';
}
?>

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
</head>
<body>
<form action="newupload.php" method="post" enctype="multipart/form-data">
    <h1>用户中心页面</h1>
    请选择头像
    <input type="file"  name="file" id="file" multiple="multiple"  >
    <br />
    <img src="" id="showImg">
    <input type="text">
    <input type="submit" id="" value="提交" />
</form>
<!--    <button onclick="showImg();">显示图片</button>-->
</body>
<script>
    var fileObj = document.getElementById('file');
    function showImg() {

        var files = fileObj['files'];
        var URL = window.URL || window.webkitURL;
        var imgURL = URL.createObjectURL(files[0]);
        document.getElementById('showImg').src = imgURL;
    }
    onload = function(){
        console.log(fileObj)
        fileObj.onchange = showImg;
    }

</script>
</html>
